<template>
  <a-card :bordered="false">
    <a-spin :spinning="loading">
      <div class="template">
        <div class="title">家长端权限</div>
        <a-list :bordered="false">
          <a-list-item class="child_list" style>
            <span class="left_title">家长端权限设置</span>
            <a-button @click="show()">设置</a-button>
          </a-list-item>
        </a-list>
      </div>
      <div class="template">
        <div class="title">消息推送</div>
        <div class="parents_client">
          <div class="all_message">
            <div class="all_message_title">所有消息</div>
            <div class="all_message_checkBox">
              <a-checkbox @change="onChangeAll($event, typeAll)" v-model="typeAll">&nbsp;微信&nbsp;</a-checkbox>

              <a-tooltip v-if="isNone">
                <template slot="title"> 短信额度已用完，请充值 </template>
                <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
              </a-tooltip>
              <a-checkbox @change="onChangeAllDX($event, typeAllDX)" v-model="typeAllDX" v-else
                >&nbsp;短信&nbsp;</a-checkbox
              >
            </div>
            <div style="width: 140px"></div>
          </div>
          <div class="message_content">
            <div class="message_head">
              <div class="message_head_title">教务消息</div>
              <div class="message_head_checkBox">
                <a-checkbox @change="onChangeEdu($event, typeEdu)" v-model="typeEdu">&nbsp;微信&nbsp;</a-checkbox>
                <a-tooltip v-if="isNone">
                  <template slot="title"> 短信额度已用完，请充值 </template>
                  <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                </a-tooltip>
                <a-checkbox @change="onChangeEduDX($event, typeEduDX)" v-model="typeEduDX" v-else
                  >&nbsp;短信&nbsp;</a-checkbox
                >
              </div>
              <div class="message_head_action" @click="showEduMsg = !showEduMsg" v-if="!showEduMsg">
                展开&nbsp;
                <a-icon type="down" />
              </div>
              <div class="message_head_action" @click="showEduMsg = !showEduMsg" v-else>
                收起&nbsp;
                <a-icon type="up" />
              </div>
            </div>
            <transition name="list" v-if="showEduMsg">
              <div class="message_child">
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">学员上课提醒</div>
                    <div class="desc">
                      上课前一天，自动发送上课提醒给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.student_attend_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'student_attend_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.student_attend_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'student_attend_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action">
                    <span class="showAction">
                      <span>每日{{ value.student_attend_remind.time }}推送</span>
                      <a
                        style="margin-left: 8px"
                        @click="showTimeModel('student_attend_remind', value.student_attend_remind.time)"
                        >修改</a
                      >
                    </span>
                  </div>
                </div>
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">学员签到通知</div>
                    <div class="desc">
                      点名后，自动发送点名信息给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.student_sign_in_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'student_sign_in_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.student_sign_in_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'student_sign_in_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">学员修改通知</div>
                    <div class="desc">
                      学员到课状态被修改后，自动发送最新到课状态给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.student_edit_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'student_edit_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <!-- <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.student_edit_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'student_edit_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    > -->
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">课时修改通知</div>
                    <div class="desc">
                      老师修改课时操作确认后，自动发送修改情况给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.class_hour_edit_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'class_hour_edit_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.class_hour_edit_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'class_hour_edit_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">订单购买通知</div>
                    <div class="desc">
                      报名后，自动发送课程购买信息给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.order_buy_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'order_buy_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.order_buy_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'order_buy_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">续费预警提醒</div>
                    <div class="desc">
                      学员剩余课时不足时，系统自动发送续费提醒给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.renewal_warning_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'renewal_warning_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.renewal_warning_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'renewal_warning_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list">
                  <div class="message_list_title">
                    <div class="title">试听报名成功通知</div>
                    <div class="desc">
                      预约/重约试听时，系统自动发送试听信息给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.audition_registration_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'audition_registration_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.audition_registration_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'audition_registration_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list" v-if="isShow">
                  <div class="message_list_title">
                    <div class="title">学员考勤通知</div>
                    <div class="desc">学员签到、签退后，自动发送考勤消息给家长</div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.attend_card_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'attend_card_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.attend_card_remind.sms_flag"
                      @change="changeTypeSingleDX($event, 'attend_card_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <!-- <div class="message_list">
              <div class="message_list_title">
                <div class="title">帐户变动提醒</div>
                <div class="desc">
                  学员充值/退款/使用余额消费时，自动发送相应提醒给学员
                  <span class="preview">预览效果</span>
                </div>
              </div>
              <div class="message_list_checkBox">
                <a-checkbox
                  v-model="value.account_change_remind.wechat_flag"
                  @change="changeTypeSingle($event,'account_change_remind',1)"
                >&nbsp;微信&nbsp;</a-checkbox>
              </div>
              <div class="message_list_action"></div>
                </div>-->
              </div>
            </transition>
          </div>
          <!-- 家校信息 -->
          <div class="message_content">
            <div class="message_head">
              <div class="message_head_title">家校信息</div>
              <div class="message_head_checkBox">
                <a-checkbox @change="onChangeSchoolHome($event, typeSchoolHome, 1)" v-model="typeSchoolHome"
                  >&nbsp;微信&nbsp;</a-checkbox
                >
                <a-tooltip v-if="isNone">
                  <template slot="title"> 短信额度已用完，请充值 </template>
                  <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                </a-tooltip>
                <a-checkbox
                  v-else
                  @change="onChangeSchoolHomeDX($event, typeSchoolHomeDX, 5)"
                  v-model="typeSchoolHomeDX"
                  >&nbsp;短信&nbsp;</a-checkbox
                >
              </div>
              <div class="message_head_action" @click="showShMsg = !showShMsg" v-if="!showShMsg">
                展开&nbsp;
                <a-icon type="down" />
              </div>
              <div class="message_head_action" @click="showShMsg = !showShMsg" v-else>
                收起&nbsp;
                <a-icon type="up" />
              </div>
            </div>
            <transition name="list" v-if="showShMsg">
              <div class="message_child">
                <div class="message_list po-la">
                  <div class="message_list_title">
                    <div class="title">作业提醒</div>
                    <div class="desc">
                      老师布置作业后，自动发送作业提醒给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.homework_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'homework_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.homework_remind.sms_flag"
                      @change="changeTypeSingle($event, 'homework_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                    <a-checkbox
                      v-model="value.homework_remind.second_reminder"
                      @change="changeTypeSingle($event, 'homework_remind', 2)"
                      class="po-ab"
                    >
                      未读学员二次提醒
                      <a-tooltip placement="top">
                        <template slot="title">针对未读信息的学员，次日同一时间系统自动发送二次提醒通知</template>
                        <a-icon type="exclamation-circle" theme="twoTone" two-tone-color="#bfbfbf" /> </a-tooltip
                      >&nbsp;&nbsp;
                    </a-checkbox>
                  </div>
                  <div class="message_list_action">
                    <!-- <span class="showAction">
                <span>每日{{value.homework_remind.time}}推送</span>
                <a style="margin-left:8px;">修改</a>
                    </span>-->
                  </div>
                </div>
                <div class="message_list po-la">
                  <div class="message_list_title">
                    <div class="title">点评提醒</div>
                    <div class="desc">
                      老师评价学员后，自动发送点评提醒给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.comment_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'comment_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.comment_remind.sms_flag"
                      @change="changeTypeSingle($event, 'comment_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                    <a-checkbox
                      v-model="value.comment_remind.second_reminder"
                      @change="changeTypeSingle($event, 'comment_remind', 2)"
                      class="po-ab"
                    >
                      未读学员二次提醒
                      <a-tooltip placement="top">
                        <template slot="title">针对未读信息的学员，次日同一时间系统自动发送二次提醒通知</template>
                        <a-icon type="exclamation-circle" theme="twoTone" two-tone-color="#bfbfbf" /> </a-tooltip
                      >&nbsp;&nbsp;
                    </a-checkbox>
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list po-la">
                  <div class="message_list_title">
                    <div class="title">成长档案提醒</div>
                    <div class="desc">
                      老师发布/回复成长档案时，自动发送消息提醒给学员
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.growth_archive_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'growth_archive_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.growth_archive_remind.sms_flag"
                      @change="changeTypeSingle($event, 'growth_archive_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                    <a-checkbox
                      v-model="value.growth_archive_remind.second_reminder"
                      @change="changeTypeSingle($event, 'growth_archive_remind', 2)"
                      class="po-ab"
                    >
                      未读学员二次提醒
                      <a-tooltip placement="top">
                        <template slot="title">针对未读信息的学员，次日同一时间系统自动发送二次提醒通知</template>
                        <a-icon type="exclamation-circle" theme="twoTone" two-tone-color="#bfbfbf" /> </a-tooltip
                      >&nbsp;&nbsp;
                    </a-checkbox>
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list po-la">
                  <div class="message_list_title">
                    <div class="title">成绩单提醒</div>
                    <div class="desc">
                      老师发布成绩单后，自动发送消息提醒让学员查看
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.school_report_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'school_report_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.school_report_remind.sms_flag"
                      @change="changeTypeSingle($event, 'school_report_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                    <a-checkbox
                      v-model="value.school_report_remind.second_reminder"
                      @change="changeTypeSingle($event, 'school_report_remind', 2)"
                      class="po-ab"
                    >
                      未读学员二次提醒
                      <a-tooltip placement="top">
                        <template slot="title">针对未读信息的学员，次日同一时间系统自动发送二次提醒通知</template>
                        <a-icon type="exclamation-circle" theme="twoTone" two-tone-color="#bfbfbf" /> </a-tooltip
                      >&nbsp;&nbsp;
                    </a-checkbox>
                  </div>
                  <div class="message_list_action"></div>
                </div>
                <div class="message_list po-la">
                  <div class="message_list_title">
                    <div class="title">机构通知</div>
                    <div class="desc">
                      机构发放通知后，自动发送消息提醒让学员查看
                      <!-- <span class="preview">预览效果</span> -->
                    </div>
                  </div>
                  <div class="message_list_checkBox">
                    <a-checkbox
                      v-model="value.school_remind.wechat_flag"
                      @change="changeTypeSingle($event, 'school_remind', 1)"
                      >&nbsp;微信&nbsp;</a-checkbox
                    >
                    <a-tooltip v-if="isNone">
                      <template slot="title"> 短信额度已用完，请充值 </template>
                      <a-checkbox :disabled="true">&nbsp;短信&nbsp;</a-checkbox>
                    </a-tooltip>
                    <a-checkbox
                      v-model="value.school_remind.sms_flag"
                      @change="changeTypeSingle($event, 'school_remind', 5)"
                      v-else
                      >&nbsp;短信&nbsp;</a-checkbox
                    >
                    <a-checkbox
                      v-model="value.school_remind.second_reminder"
                      @change="changeTypeSingle($event, 'school_remind', 2)"
                      class="po-ab"
                    >
                      未读学员二次提醒
                      <a-tooltip placement="top">
                        <template slot="title">针对未读信息的学员，次日同一时间系统自动发送二次提醒通知</template>
                        <a-icon type="exclamation-circle" theme="twoTone" two-tone-color="#bfbfbf" /> </a-tooltip
                      >&nbsp;&nbsp;
                    </a-checkbox>
                  </div>
                  <div class="message_list_action"></div>
                </div>
              </div>
            </transition>
          </div>
        </div>
      </div>

      <a-modal
        title="修改上课提醒时间"
        :visible="changeTimeVisible"
        :confirm-loading="confirmLoading"
        @ok="handleOk"
        @cancel="changeTimeVisible = false"
      >
        <a-alert message="修改时间将于次日生效" type="info" show-icon />
        <div style="padding: 20px 0">
          <span>修改上课提醒时间：</span>
          <span>
            <a-time-picker v-model="defaultTime" format="HH:mm" @change="changeTime" />
          </span>
        </div>
      </a-modal>
      <parent-setting ref="parentSetting"></parent-setting>
    </a-spin>
  </a-card>
</template>

<script>
import { parentsList, changeChecked } from '@/api/parentClient'
import { getInfo } from '@/api/shortMessage'
import parentSetting from './parentClientComponents/parentSetting'
import moment from 'moment'
export default {
  name: 'qqq',
  data() {
    return {
      surplusMsg: 0,
      showEduMsg: true,
      showShMsg: true,
      activeKey: ['1', '2'],
      value: {
        student_attend_remind: {
          template: {},
          time: '17:00',
          wechat_flag: false,
        },
        student_sign_in_remind: {
          template: {},
          wechat_flag: false,
        },
        student_edit_remind: {
          template: {},
          wechat_flag: false,
        },
        class_hour_edit_remind: {
          template: {},
          wechat_flag: false,
        },
        order_buy_remind: {
          template: {},
          wechat_flag: false,
        },
        renewal_warning_remind: {
          template: {},
          wechat_flag: false,
        },
        audition_registration_remind: {
          template: {},
          wechat_flag: false,
        },
        attend_card_remind: {
          template: {},
          wechat_flag: false,
        },
        // account_change_remind: {
        //   template: {},
        //   wechat_flag: false
        // },
        homework_remind: {
          template: {},
          second_reminder: false,
          wechat_flag: false,
        },
        comment_remind: {
          template: {},
          second_reminder: false,
          wechat_flag: false,
        },
        growth_archive_remind: {
          template: {},
          second_reminder: false,
          wechat_flag: false,
        },
        school_report_remind: {
          template: {},
          second_reminder: false,
          wechat_flag: false,
        },
        school_remind: {
          template: {},
          second_reminder: false,
          wechat_flag: false,
        },
        apply_leave: true,
        evaluate_teacher: true,
        class_hour_search: true,
        school_report: true,
        surplus_class_hour: true,
        recharge_balance: true,
        my_order: true,
      },
      typeAll: false,
      typeAllDX: false,
      typeEdu: false,
      typeEduDX: false,
      typeSchoolHome: false,
      typeSchoolHomeDX: false,
      confirmLoading: false,
      // 时间弹框
      changeTimeVisible: false,
      // 修改时间的元素
      item_key: '',
      //要修改的时间
      time: '',
      defaultTime: null,
      loading: false,
      isShow: true,
    }
  },
  components: {
    parentSetting,
  },
  created() {
    this.getList()
    this.getNumber()
  },
  computed: {
    isNone() {
      return this.surplusMsg == 0 ? true : false
    },
  },
  methods: {
    getNumber() {
      getInfo({ school_id: this.$store.state.user.school }).then((res) => {
        let id = this.$store.state.user.school
        const schools = res.schools
        // if()
        schools.forEach((e) => {
          if (e.id == id) {
            this.surplusMsg = e.sms_surplus
          }
        })
      })
    },
    show() {
      this.$nextTick(() => {
        this.$refs.parentSetting.showModel()
      })
    },
    changeTime(date, dateString) {
      this.time = dateString
    },
    //修改时间
    showTimeModel(e, data) {
      if (e) {
        this.item_key = e
        this.defaultTime = moment(data, 'HH:mm')
      }
      this.changeTimeVisible = true
    },
    //修改时间确定事件
    handleOk() {
      this.confirmLoading = true
      changeChecked({
        school_id: this.$store.state.user.school,
        key: 'parent_management',
        data: [
          {
            item_key: this.item_key,
            type: 3,
            time: this.time,
          },
        ],
      })
        .then((res) => {
          this.getList()
          this.$message.success('修改时间成功~')
          this.confirmLoading = false
          this.changeTimeVisible = false
        })
        .catch((err) => {
          this.getList()
          this.$message.error(err.data.message || '修改时间失败,请稍后重试~')
          this.confirmLoading = false
        })
    },
    getList() {
      this.loading = true
      parentsList({
        school_id: this.$store.state.user.school,
        key: 'parent_management',
      })
        .then((res) => {
          if (res.value && !(res.value instanceof Array)) {
            // this.value = res.value
            let value = JSON.parse(JSON.stringify(this.value))
            for (let x in value) {
              for (let y in res.value) {
                if (x == y) {
                  if (res.value[y].wechat_flag) {
                    value[x].wechat_flag = true
                  } else {
                    value[x].wechat_flag = false
                  }
                  if (res.value[y].sms_flag) {
                    value[x].sms_flag = true
                  } else {
                    value[x].sms_flag = false
                  }
                  if (res.value[y].time) {
                    value[x].time = res.value[y].time
                  }
                  if (value[x].second_reminder !== undefined) {
                    if (res.value[y].second_reminder !== undefined) {
                      value[x].second_reminder = res.value[y].second_reminder
                    } else {
                      value[x].second_reminder = false
                    }
                  }
                }
              }
            }
            this.value = value
            let edu = false
            let dx = false
            let sh = false //家校
            let all = false //所有
            //教务
            this.typeEdu = false
            let num = 0
            for (let i in value) {
              if (value[i].wechat_flag !== undefined && value[i].second_reminder == undefined) num++
            }
            let resNum = 0
            for (let i in value) {
              if (value[i] && value[i].wechat_flag && value[i].second_reminder == undefined) {
                resNum++
                if (resNum == num) {
                  edu = true
                  this.typeEdu = true
                }
              }
            }
            //短信
            let DXnum = 0
            for (let i in value) {
              if (!value[i].sms_flag) DXnum++
            }
            let resNumDX = 0
            for (let i in value) {
              if (value[i] && value[i].sms_flag) {
                resNumDX++
                if (resNumDX == DXnum) {
                  dx = true
                  this.typeEduDX = true
                }
              }
            }

            //家校
            this.typeSchoolHome = false
            this.typeSchoolHomeDX = false
            let num1 = 0
            for (let i in value) {
              if (value[i].second_reminder !== undefined) num1++
            }
            let resNum1 = 0
            for (let i in value) {
              if (value[i] && value[i].wechat_flag && value[i].second_reminder !== undefined) {
                resNum1++
                if (resNum1 == num1) {
                  sh = true
                  this.typeSchoolHome = true
                }
              }
            }
            //短信
            // let num1DX = 0
            // for (let i in value) {
            //   if (value[i].sms_flag !== undefined) num1DX++
            // }
            // let resNum1DX = 0
            // for (let i in value) {
            //   if (value[i] && value[i].sms_flag ) {
            //     resNum1DX++
            //     if (resNum1DX == num1DX) {
            //       sh = true
            //       this.typeSchoolHomeDX = true
            //     }
            //   }
            // }

            if (edu == true && sh == true) {
              this.typeAll = true
            } else {
              this.typeAll = false
            }
            if (dx == true && sh == true) {
              this.typeAllDX = true
            } else {
              this.typeAllDX = false
            }
            let arr1 = [
              'school_remind',
              'school_report_remind',
              'growth_archive_remind',
              'comment_remind',
              'homework_remind',
            ]
            var s = 0
            var dxsh = 5
            for (let i in value) {
              if (arr1.indexOf(i) != -1) {
                if (value[i].sms_flag) {
                  s++
                }
              }
            }
            if (s == dxsh) {
              this.typeSchoolHomeDX = true
            } else {
              this.typeSchoolHomeDX = false
            }
            var arr = [
              'student_attend_remind',
              'student_sign_in_remind',
              'student_edit_remind',
              'class_hour_edit_remind',
              'order_buy_remind',
              'renewal_warning_remind',
              'audition_registration_remind',
              'attend_card_remind',
            ]
            var s1 = 0
            var dxsh1 = 8
            for (let i in value) {
              if (arr.indexOf(i) != -1) {
                if (value[i].sms_flag) {
                  s1++
                }
              }
            }
            if (s1 == dxsh1) {
              this.typeEduDX = true
            } else {
              this.typeEduDX = false
            }
            if (this.typeEduDX && this.typeSchoolHomeDX) {
              this.typeAllDX = true
            } else {
              this.typeAllDX = false
            }
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    changeTypeSingle(e, params, typeNum) {
      this.loading = true
      changeChecked({
        school_id: this.$store.state.user.school,
        key: 'parent_management',
        data: [
          {
            item_key: params,
            type: typeNum,
            flag: e.target.checked,
          },
        ],
      })
        .then((res) => {
          this.getList()
        })
        .catch((err) => {
          if (e.target.checked) {
            this.getList()
            this.$message.error(err.data.message || '开启失败,请稍后重试~')
          } else {
            this.getList()
            this.$message.error(err.data.message || '关闭失败,请稍后重试~')
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    changeTypeSingleDX(e, params, typeNum) {
      this.loading = true
      changeChecked({
        school_id: this.$store.state.user.school,
        key: 'parent_management',
        data: [
          {
            item_key: params,
            type: typeNum,
            flag: e.target.checked,
          },
        ],
      })
        .then((res) => {
          this.getList()
        })
        .catch((err) => {
          if (e.target.checked) {
            this.getList()
            this.$message.error(err.data.message || '开启失败,请稍后重试~')
          } else {
            this.getList()
            this.$message.error(err.data.message || '关闭失败,请稍后重试~')
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    //教务消息
    onChangeEdu(e, params) {
      var that = this
      this.$confirm({
        title: '提示',
        content: params == true ? '确定批量开启微信？' : '确定批量关闭微信',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          that.loading = true
          changeChecked({
            school_id: that.$store.state.user.school,
            key: 'parent_management',
            data: [
              {
                item_key: 'student_attend_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'student_sign_in_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'student_edit_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'class_hour_edit_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'order_buy_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'renewal_warning_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'audition_registration_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'attend_card_remind',
                type: 1,
                flag: e.target.checked,
              },
              // {
              //   item_key: 'account_change_remind',
              //   type: 1,
              //   flag: e.target.checked
              // }
            ],
          })
            .then((res) => {
              that.getList()
            })
            .catch((err) => {
              that.loading = false
              if (e.target.checked) {
                that.getList()
                that.$message.error('批量开启失败,请稍后重试~')
              } else {
                that.getList()
                that.$message.error('批量关闭失败,请稍后重试~')
              }
            })
        },
        onCancel() {
          that.typeEdu = !params
        },
      })
    },
    onChangeEduDX(e, params) {
      var that = this
      this.$confirm({
        title: '提示',
        content: params == true ? '确定批量开启短信？' : '确定批量关闭短信',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          const arr = [
            {
              item_key: 'student_attend_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'student_sign_in_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'student_edit_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'class_hour_edit_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'order_buy_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'renewal_warning_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'audition_registration_remind',
              type: 5,
              flag: e.target.checked,
            },
            {
              item_key: 'attend_card_remind',
              type: 5,
              flag: e.target.checked,
            },
          ]
          const sendData = arr.map((item) => {
            return {
              item_key: item.item_key,
              type: 5,
              flag: e.target.checked,
            }
          })
          that.loading = true
          changeChecked({
            school_id: that.$store.state.user.school,
            key: 'parent_management',
            data: sendData,
          })
            .then((res) => {
              that.getList()
            })
            .catch((err) => {
              that.loading = false
              if (e.target.checked) {
                that.getList()
                that.$message.error('批量开启失败,请稍后重试~')
              } else {
                that.getList()
                that.$message.error('批量关闭失败,请稍后重试~')
              }
            })
        },
        onCancel() {
          that.typeEduDX = !params
        },
      })
    },
    //家校消息
    onChangeSchoolHome(e, params, type) {
      var that = this
      this.$confirm({
        title: '提示',
        content: params == true ? '确定批量开启微信？' : '确定批量关闭微信',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          that.loading = true
          changeChecked({
            school_id: that.$store.state.user.school,
            key: 'parent_management',
            data: [
              {
                item_key: 'homework_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'comment_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'growth_archive_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'school_report_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'school_remind',
                type,
                flag: e.target.checked,
              },
            ],
          })
            .then((res) => {
              that.getList()
            })
            .catch((err) => {
              that.loading = false
              if (e.target.checked) {
                that.getList()
                that.$message.error('批量开启失败,请稍后重试~')
              } else {
                that.getList()
                that.$message.error('批量关闭失败,请稍后重试~')
              }
            })
        },
        onCancel() {
          that.typeSchoolHome = !params
        },
      })
    },
    onChangeSchoolHomeDX(e, params, type) {
      var that = this
      this.$confirm({
        title: '提示',
        content: params == true ? '确定批量开启微信？' : '确定批量关闭微信',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          that.loading = true
          changeChecked({
            school_id: that.$store.state.user.school,
            key: 'parent_management',
            data: [
              {
                item_key: 'homework_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'comment_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'growth_archive_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'school_report_remind',
                type,
                flag: e.target.checked,
              },
              {
                item_key: 'school_remind',
                type,
                flag: e.target.checked,
              },
            ],
          })
            .then((res) => {
              that.getList()
            })
            .catch((err) => {
              that.loading = false
              if (e.target.checked) {
                that.getList()
                that.$message.error('批量开启失败,请稍后重试~')
              } else {
                that.getList()
                that.$message.error('批量关闭失败,请稍后重试~')
              }
            })
        },
        onCancel() {
          that.typeSchoolHomeDX = !params
        },
      })
    },
    onChangeAll(e, params) {
      var that = this
      this.$confirm({
        title: '提示',
        content: params == true ? '确定批量开启微信？' : '确定批量关闭微信',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          that.loading = true
          changeChecked({
            school_id: that.$store.state.user.school,
            key: 'parent_management',
            data: [
              {
                item_key: 'student_attend_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'student_sign_in_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'student_edit_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'class_hour_edit_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'order_buy_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'renewal_warning_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'audition_registration_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'attend_card_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'homework_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'comment_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'growth_archive_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'school_report_remind',
                type: 1,
                flag: e.target.checked,
              },
              {
                item_key: 'school_remind',
                type: 1,
                flag: e.target.checked,
              },
            ],
          })
            .then((res) => {
              that.getList()
            })
            .catch((err) => {
              that.loading = false
              if (e.target.checked) {
                that.getList()
                that.$message.error('批量开启失败,请稍后重试~')
              } else {
                that.getList()
                that.$message.error('批量关闭失败,请稍后重试~')
              }
            })
        },
        onCancel() {
          that.typeAll = !params
        },
      })
    },
    onChangeAllDX(e, params) {
      var that = this
      this.$confirm({
        title: '提示',
        content: params == true ? '确定批量开启短信？' : '确定批量关闭短信',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          that.loading = true
          let arr = [
            {
              item_key: 'attend_card_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'student_attend_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'student_sign_in_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'student_edit_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'class_hour_edit_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'order_buy_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'renewal_warning_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'audition_registration_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'homework_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'comment_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'growth_archive_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'school_report_remind',
              type: 1,
              flag: e.target.checked,
            },
            {
              item_key: 'school_remind',
              type: 1,
              flag: e.target.checked,
            },
          ]
          const arrCP = arr.map((item) => {
            return {
              type: 5,
              item_key: item.item_key,
              flag: e.target.checked,
            }
          })
          changeChecked({
            school_id: that.$store.state.user.school,
            key: 'parent_management',
            data: arrCP,
          })
            .then((res) => {
              that.getList()
            })
            .catch((err) => {
              that.loading = false
              if (e.target.checked) {
                that.getList()
                //  that.typeAllDX = !params
                that.$message.error('批量开启失败,请稍后重试~')
              } else {
                that.getList()
                that.$message.error('批量关闭失败,请稍后重试~')
              }
            })
        },
        onCancel() {
          that.typeAllDX = !params
        },
      })
    },
  },
  watch: {
    changeTimeVisible(val) {
      if (val == false) {
        this.item_key = ''
        this.time = ''
      }
    },
  },
}
</script>
<style lang="less">
.child_list.ant-list-item {
  justify-content: flex-start !important;
  border-bottom: none;
}
</style>
<style lang="less" scoped>
.po-la {
  position: relative;
}
.po-ab {
  position: absolute;
  right: 0;
}
.template {
  .title {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    line-height: 22px;
  }
}
.child_list {
  padding: 12px 26px;
  .left_title {
    display: inline-block;
    width: 250px;
    margin-right: 30px;
  }
  .config_description {
    margin-left: 30px;
    color: #909090;
  }
}
.parents_client {
  margin-top: 10px;
  background: #fff;
  border: 1px solid #e8e8e8;
  .all_message {
    padding: 0 24px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f7f8f9;
    border-bottom: 1px solid #e8e8e8;
    .all_message_title {
      width: 500px;
      font-size: 14px;
      font-weight: 600;
      color: #333;
      line-height: 20px;
    }
    .all_message_checkBox {
      width: 500px;
      display: flex;
      justify-content: space-between;
    }
  }
}
.message_content {
  border-bottom: 1px solid #e8e8e8;
  .message_head {
    border-left: 4px solid #ccc;
    padding: 0 24px 0 20px;
    height: 50px;
    line-height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .message_head_title {
      width: 500px;
      font-size: 14px;
      font-weight: 600;
      color: #333;
    }
    .message_head_checkBox {
      width: 500px;
      display: flex;
      justify-content: space-between;
    }
    .message_head_action {
      width: 140px;
      text-align: right;
      cursor: pointer;
    }
  }
  .message_child {
    .message_list {
      border-bottom: 1px dashed #e8e8e8;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 20px;
      .message_list_title {
        width: 500px;
        .title {
          color: rgb(51, 51, 51);
        }
        .desc {
          color: rgb(153, 153, 153);
          .preview {
            color: rgb(88, 183, 239);
            margin-left: 8px;
            cursor: pointer;
          }
        }
      }
      .message_list_checkBox {
        width: 500px;
        display: flex;
        justify-content: space-between;
      }
      .message_list_action {
        width: 140px;
        text-align: right;
      }
    }
    .message_list:first-child {
      border-top: 1px solid #e8e8e8;
    }
    .message_list:last-child {
      border-bottom: none;
    }
  }
}
.message_content:last-child {
  border-bottom: none;
}
.list-item {
  display: inline-block;
  margin-right: 10px;
}
.list-enter-active,
.list-leave-active {
  transition: all 0.2s;
}
.list-enter, .list-leave-to
/* .list-leave-active for below version 2.1.8 */ {
  opacity: 0;
  transform: translateY(-5px);
}
</style>